package b3.widget.home.user
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.scene.*;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	import b3.widget.vip.*;
	import b3.widget.home.town.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.net.*;
	import flash.text.*;

	public class PlayerPane extends Sprite
	{
		private var playerId:int;
		public var statePane:StatePane;
		public var lightPane:LightPane;
		public var darkPane:DarkPane;
		private var pictLdr:Loader;
		
		public function PlayerPane(playerId:int)
		{
			super();
			this.playerId = playerId;
			var playerInfo:Player = PlayerManager.getInstance().players[playerId];
			//用户背景框
			var UserPicPaneBgr:Class = ResourceHelper.getInstance().getClassByName("UserPicPaneBgr");
			var userPicPaneBgr:Sprite = new UserPicPaneBgr();
			addChild(userPicPaneBgr);
			//获得用户头像
			if (playerInfo.figureurl != null)
			{
				pictLdr = new Loader();
				var pictURLReq:URLRequest = new URLRequest(playerInfo.figureurl);
				pictLdr.load(pictURLReq);
				pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, onUserPicLoaded);
				addChild(pictLdr);
			}
			//黄钻图标
			if (playerInfo.is_yellow_vip || playerInfo.is_yellow_year_vip)
			{
				var vipIcon:VipIcon = new VipIcon(playerInfo.yellow_vip_level, playerInfo.is_yellow_year_vip);
				vipIcon.x = 75;
				vipIcon.y = -3;
				addChild(vipIcon);
			}
			//用户名字
			var userName:TextField = new TextField();
        	userName.autoSize = TextFieldAutoSize.CENTER;
			userName.selectable = false;
			userName.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x0088FF, true);
			userName.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			userName.x = 50;
			userName.y = 10;
			userName.text = playerInfo.name.substr(0,4);
			addChild(userName);
			//人口
			var populationPane:PopulationPane = new PopulationPane();
			populationPane.x = 91.8;
			populationPane.y = 22.6;
			addChild(populationPane);
			//光明
			lightPane = new LightPane();
			lightPane.x = 89.2;
			lightPane.y = 54.5;
			addChild(lightPane);
			//黑暗
			darkPane = new DarkPane();
			darkPane.x = 71.1;
			darkPane.y = 86.5;
			addChild(darkPane);
			//状态栏
			statePane = new StatePane();
			statePane.x = 62;
			statePane.y = -5;
			addChild(statePane);
			//管理员
			if (playerInfo.type == PlayerManager.MANAGER_TYPE)
			{
				var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr1");
				var adminButton:BasicButton = new BasicButton(ButtonBgr, "管理");
				adminButton.x = 0;
				adminButton.y = 100;
				adminButton.addEventListener(MouseEvent.CLICK, onAdminButtonClick);
				addChild(adminButton);
			}
		}
		
		private function onAdminButtonClick(event:MouseEvent):void
		{
			var adminPane:AdminPane = new AdminPane();
			WidgetManager.getInstance().popOut([adminPane], true);
		}
		
		private function onUserPicLoaded(event:Event):void
		{
			pictLdr.x = 50 - pictLdr.width / 2;
			pictLdr.y = 55 - pictLdr.height / 2;
		}
		
	}
}